import { JSEncrypt } from 'jsencrypt'

const jsencrypt = new JSEncrypt()
// jsencrypt.getKey()
// const publicKey = jsencrypt.getPublicKey()
// const privateKey = jsencrypt.getPrivateKey()
const publicKey = `-----BEGIN PUBLIC KEY-----
MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgFq+PpawHP9EiJxPzAc/EOPsu6tn
B/z6dfyM/xAyPgIjxKfFz1a4iWeqN9n/+rtTL40dwA+Lt9IQY841EfPjG8Mvap7A
0OSM05z93ddqBEDkpydy9+iBx3o9rV+Vi7ZQI+9bjh/Ohrc35z+/iid984jiY75L
xKXMSVwcP4mmzR7VAgMBAAE=
-----END PUBLIC KEY-----`

const privateKey = `-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgFq+PpawHP9EiJxPzAc/EOPsu6tnB/z6dfyM/xAyPgIjxKfFz1a4
iWeqN9n/+rtTL40dwA+Lt9IQY841EfPjG8Mvap7A0OSM05z93ddqBEDkpydy9+iB
x3o9rV+Vi7ZQI+9bjh/Ohrc35z+/iid984jiY75LxKXMSVwcP4mmzR7VAgMBAAEC
gYAIsJdFzu+38lQyw+GCACQZ7525OFCnhUSvPsFeR7FwewRmHKdSYrGl38MheUYF
kl3HYcX2tyaPU0p7gNGLTYBm/xJ6xYmhSjA4hsV2jlWhRql67jmigTzZN/YiZc4X
pkrlXV/lKKdZY1DU6lKPAmvk3zHUu1bXehADC9jilkj/AQJBALSbUYpm0rNxv+Yh
R3skPhM4x+mCDOrLDa4kFg5reXr+HccYPxWAUotmT3L620+Nutp/M6LiLUEXjd4W
25xQrqUCQQCAn5VUQadP8FsYJRguVlGc8actQE+kt8vQVnKlnfnB9DtMIO4+JNI1
obmC6fX9+8dg3lgx9R6a4P7e4CMPuWhxAkEArU59qHmSpm743jQBC8Fzb66E5yXM
j2HZ9sjaAWxQXh2LJYm2v0Mr8mhyxLrDyEsQiqqVOjAfjN61W/BDPHSPoQJAMo0F
pnirJirD0oh5qXR5XOJInutAoe8uZjIjmt2slELFr1Td7YSRLUzjWQVUjb6PjI22
QeQhZCN7Z+LVRM/MsQJAZBZHpZBtA5dkHWv01zqtLaNrueTZmKnAzg/DXcfdE4+H
kPyYEOhvpEzZq3tg+XzArItscUeenw9qI6gZ0N4TPQ==
-----END RSA PRIVATE KEY-----`

export const encrypt = (text) => {
  jsencrypt.setPublicKey(publicKey)
  const encryptedData = jsencrypt.encrypt(text)
  console.log(encryptedData)
  return encryptedData
}

export const decrypt = (encryptedData) => {
  jsencrypt.setPrivateKey(privateKey);
  const decryptedData = jsencrypt.decrypt(encryptedData);
  console.log(decryptedData)
  return decryptedData
}
